package cn.tannn.ops.message.constant;

import lombok.AllArgsConstructor;
import lombok.Getter;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.Objects;

/**
 * webhook 所属地址
 *
 * @author <a href="https://t.tannn.cn/">tan</a>
 * @version V1.0
 * @date 2024/8/23 上午10:45
 */
@AllArgsConstructor
@Getter
public enum WebHookApp {

    /**
     * 钉钉
     */
    DINGTALK("钉钉", "dingtalk"),
    /**
     * 企业微信
     */
    WECHAT("企业微信", "wechat"),
    /**
     * 飞书
     */
    FEISHU("飞书", "feishu");

    private final String name;
    private final String app;


    /**
     * 获取枚举实例
     */
    public static WebHookApp fromName(String name) {
        for (WebHookApp webHookApp : WebHookApp.values()) {
            if (Objects.equals(name, webHookApp.getName())) {
                return webHookApp;
            }
        }
        throw new IllegalArgumentException();
    }


    /**
     * to map
     * @return {name:xx,app:yy}
     */
    public static List<Map<String,String>> toMap(){
        List<Map<String, String>> maps = new ArrayList<>();
        for (WebHookApp value : WebHookApp.values()) {
            maps.add(Map.of("name",value.getName(),"app",value.getApp().toUpperCase()));
        }
        return maps;
    }
}
